Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[lang]: allow downcasting of bytestrings #3832

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Mar 5, 2024

What I did

How I did it

How to verify it

Commit message

this commit extends `convert()` to allow downcasting of Bytes/Strings,
i.e. converting `Bytes[20]` to `Bytes[19]`.

this improves the UX of bytestrings somewhat, since currently (prior to
this commit) there is no type-safe way to decrease the size of a
bytestring in vyper. it also prepares us a little bit for adding generic
bytestrings inside the type system (`Bytes[...]`) which can only be
user-instantiated by `convert`ing to a known length.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

allow conversion from Bytes/String types to shorter length types, e.g.
convert `Bytes[20]` to `Bytes[19]`

this will become important when we want to allow generic bytestrings
inside the type system (`Bytes[...]`) which can only be
user-instantiated by converting to a known length.
@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 86.01%. Comparing base (cf37ec2) to head (5348802).

Files Patch % Lines
vyper/builtins/_convert.py 87.50% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3832      +/-   ##
==========================================
- Coverage   86.15%   86.01%   -0.14%     
==========================================
  Files          92       92              
  Lines       13923    13931       +8     
  Branches     3068     3071       +3     
==========================================
- Hits        11995    11983      -12     
- Misses       1491     1509      +18     
- Partials      437      439       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@charles-cooper charles-cooper marked this pull request as ready for review March 6, 2024 16:12
@charles-cooper charles-cooper mentioned this pull request Mar 6, 2024
33 tasks
@charles-cooper charles-cooper added this to the v0.4.0 milestone Mar 6, 2024
@charles-cooper charles-cooper merged commit 9cfe7b4 into vyperlang:master Mar 12, 2024
83 checks passed
@charles-cooper charles-cooper deleted the feat/bytestring-cast branch March 12, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants